package dao.impl;

import dao.TouristDao;
import entity.Tourist;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class TouristDaoImpl implements TouristDao {
    private SqlSession sqlSession;
    @Override
    public int insert(Tourist tourist){
        sqlSession = SqlSessionUtil.getSqlSession();
        int result = sqlSession.insert("TouristMapper.insert",tourist);
        sqlSession.close();
        return result;
    }

    @Override
    public int delete(int id){
        sqlSession = SqlSessionUtil.getSqlSession();
        int result = sqlSession.delete("TouristMapper.delete",id);
        sqlSession.close();
        return result;
    }

    @Override
    public int update(Tourist tourist){
        sqlSession = SqlSessionUtil.getSqlSession();
        int result = sqlSession.update("TouristMapper.update",tourist);
        sqlSession.close();
        return result;
    }

    @Override
    public Tourist getOne(int id){
        sqlSession = SqlSessionUtil.getSqlSession();
        Tourist tourist = sqlSession.selectOne("TouristMapper.getOne",id);
        sqlSession.close();
        return tourist;
    }

    @Override
    public List<Tourist> getList(Tourist tourist){
        sqlSession = SqlSessionUtil.getSqlSession();
        List<Tourist> touristList = sqlSession.selectList("TouristMapper.getList",tourist);
        sqlSession.close();
        return touristList;
    }

}
